/* $Header: ramp_init.c,v 2.2 01/10/02 10:32:29 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:  ramp_init.c                                           */
/* ============                                                        */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* MODULE PURPOSE:  To provide functions for initializing the ramp     */
/*                  generator setpts and state.                        */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <i_op.h>
#include <zone_config.h>
#include <zone_status.h>
#include <p_status.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/

void InitRamps( void )
{


  Oven_Temp_Info.num_ramps      = OVEN_RAMP_LEVELS;
  Oven_Temp_Info.ramp_enabled   = TRUE;
  Oven_Temp_Info.ramps          = Active_Wkfile.oven_ramps;
  Oven_Temp_Info.ramp_table     = &Active_Wkfile.oven_temp;
  Oven_Temp_Info.setpoint       = (U_INT32 *)&Oven_Table.temp_setpt;


     /* Set up pointers to the ramp information structures.            */
  Inja_Temp_Info.num_ramps      = RAMP_LEVELS;
  Inja_Temp_Info.ramp_enabled   = TRUE;
  Inja_Temp_Info.ramps          = Active_Wkfile.inja_ramps;
  Inja_Temp_Info.ramp_table     = &Active_Wkfile.inja_temp;
  Inja_Temp_Info.setpoint       = (U_INT32 *)&Inja_Table.temp_setpt;

  Injb_Temp_Info.num_ramps      = RAMP_LEVELS;
  Injb_Temp_Info.ramp_enabled   = TRUE;
  Injb_Temp_Info.ramps          = Active_Wkfile.injb_ramps;
  Injb_Temp_Info.ramp_table     = &Active_Wkfile.injb_temp;
  Injb_Temp_Info.setpoint       = (U_INT32 *)&Injb_Table.temp_setpt;

  Col1_Pres_Info.num_ramps      = RAMP_LEVELS;
  Col1_Pres_Info.ramp_enabled   = TRUE;
  Col1_Pres_Info.ramps          =  Active_Wkfile.Pneu.Column_1.Ramp_Rates;
  Col1_Pres_Info.ramp_table     = &Active_Wkfile.Pneu.Column_1.Ramp_Init_And_Post_Values;
  Col1_Pres_Info.setpoint       = &Inst_Status.Pneu.Column_1.Ramp_Setpt.Head_Pressure;

  Col2_Pres_Info.num_ramps      = RAMP_LEVELS;
  Col2_Pres_Info.ramp_enabled   = TRUE;
  Col2_Pres_Info.ramps          =  Active_Wkfile.Pneu.Column_2.Ramp_Rates;
  Col2_Pres_Info.ramp_table     = &Active_Wkfile.Pneu.Column_2.Ramp_Init_And_Post_Values;
  Col2_Pres_Info.setpoint       = &Inst_Status.Pneu.Column_2.Ramp_Setpt.Head_Pressure;

  Deta_Temp_Info.num_ramps      = DET_RAMP_LEVELS;
  Deta_Temp_Info.ramp_enabled   = TRUE;
  Deta_Temp_Info.ramps          = Active_Wkfile.deta_ramps;
  Deta_Temp_Info.ramp_table     = &Active_Wkfile.deta_temp;
  Deta_Temp_Info.setpoint       = (U_INT32 *)&Deta_Table.temp_setpt;

  Detb_Temp_Info.num_ramps      = DET_RAMP_LEVELS;
  Detb_Temp_Info.ramp_enabled   = TRUE;
  Detb_Temp_Info.ramps          = Active_Wkfile.detb_ramps;
  Detb_Temp_Info.ramp_table     = &Active_Wkfile.detb_temp;
  Detb_Temp_Info.setpoint       = (U_INT32 *)&Detb_Table.temp_setpt;

  Aux1_Temp_Info.num_ramps      = RAMP_LEVELS;
  Aux1_Temp_Info.ramp_enabled   = TRUE;
  Aux1_Temp_Info.ramps          = Active_Wkfile.auxa_ramps;
  Aux1_Temp_Info.ramp_table     = &Active_Wkfile.auxa_temp;
  Aux1_Temp_Info.setpoint       = (U_INT32 *)&Auxa_Table.temp_setpt;

  Aux2_Temp_Info.num_ramps      = RAMP_LEVELS;
  Aux2_Temp_Info.ramp_enabled   = TRUE;
  Aux2_Temp_Info.ramps          = Active_Wkfile.auxb_ramps;
  Aux2_Temp_Info.ramp_table     = &Active_Wkfile.auxb_temp;
  Aux2_Temp_Info.setpoint       = (U_INT32 *)&Auxb_Table.temp_setpt;

  Aux3_Pres_Info.num_ramps      = RAMP_LEVELS;
  Aux3_Pres_Info.ramp_enabled   = FALSE;
  Aux3_Pres_Info.ramps          =  Active_Wkfile.Pneu.Aux_3.Ramp_Rates;
  Aux3_Pres_Info.ramp_table     = &Active_Wkfile.Pneu.Aux_3.Ramp_Init_And_Post_Values;
  Aux3_Pres_Info.setpoint       = &Inst_Status.Pneu.Aux.Aux_3.Ramp_Setpt.Ramp_Pressure;

  Aux4_Pres_Info.num_ramps      = RAMP_LEVELS;
  Aux4_Pres_Info.ramp_enabled   = FALSE;
  Aux4_Pres_Info.ramps          =  Active_Wkfile.Pneu.Aux_4.Ramp_Rates;
  Aux4_Pres_Info.ramp_table     = &Active_Wkfile.Pneu.Aux_4.Ramp_Init_And_Post_Values;
  Aux4_Pres_Info.setpoint       = &Inst_Status.Pneu.Aux.Aux_4.Ramp_Setpt.Ramp_Pressure;

  Aux5_Pres_Info.num_ramps      = RAMP_LEVELS;
  Aux5_Pres_Info.ramp_enabled   = FALSE;
  Aux5_Pres_Info.ramps          =  Active_Wkfile.Pneu.Aux_5.Ramp_Rates;
  Aux5_Pres_Info.ramp_table     = &Active_Wkfile.Pneu.Aux_5.Ramp_Init_And_Post_Values;
  Aux5_Pres_Info.setpoint       = &Inst_Status.Pneu.Aux.Aux_5.Ramp_Setpt.Ramp_Pressure;


}


/***********************************************************************/
/* FUNCTION: SetThermalRampDefault                                            */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To initialize a ramp setpt profile to default values.     */
/*                                                                     */
/* RETURNED VALUE:  none                                               */
/*                                                                     */
/* GLOBALS USED:  Active_Wkfile                                        */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

void SetThermalRampDefault( RAMPTBL *ptbl, RAMPS *pramp, INT32 setpt, U_INT32 levels )
{
   U_INT32 i;

   ptbl->init_time  = 0;
   ptbl->init_value = setpt;
   ptbl->post_value = setpt;

   for ( i= 0; i < levels; i++ )
   {
      pramp->final_value = setpt;
      pramp->final_time  = 0;
      pramp->rate        = 0;
      pramp++;
   }

   ptbl->ramp_type = THERMAL_RAMP;
}



/***********************************************************************/
/* FUNCTION: SetThermalRampDefault                                            */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  To initialize a ramp setpt profile to default values.     */
/*                                                                     */
/* RETURNED VALUE:  none                                               */
/*                                                                     */
/* GLOBALS USED:  Active_Wkfile                                        */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

void SetPressureRampDefault( RAMPINFO *ramp_info )
{
   U_INT32 i;
   RAMPTBL *ptbl;
   RAMPS   *pramp;

   ptbl  = ramp_info->ramp_table;
   pramp = ramp_info->ramps;

   ptbl->init_time  = 0;
   ptbl->init_value = 0;
   ptbl->post_value = 0;

   for ( i= 0; i < ramp_info->num_ramps; i++ )
   {
      pramp->final_value = 0;
      pramp->final_time  = 0;
      pramp->rate        = 0;
      pramp++;
   }

   ptbl->ramp_type = PRESSURE_RAMP;
}




/***********************************************************************/
/* FUNCTION:  SetPresRampDefaults                                      */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

void SetPresRampDefaults (void)
{

  SetPressureRampDefault( &Aux3_Pres_Info );
  SetPressureRampDefault( &Aux4_Pres_Info );
  SetPressureRampDefault( &Aux5_Pres_Info );

}



/***********************************************************************/
/* FUNCTION: UpdateZoneInitValues                                      */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:  This functions sets the initial values for the oven and   */
/*           thermal zones, and is called from UpdateInstStatus        */
/*           (wkfileutil.c).                                           */
/*                                                                     */
/* RETURNED VALUE:  None.                                              */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*               ZONE_TABLE's                                          */
/*               Active_Wkfile                                         */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/***********************************************************************/

void UpdateZoneInitValues (void)
{
  /* Set the current setpoints to the values in the workfile.          */

  INTERRUPTS_OFF

  Oven_Table.temp_setpt = Active_Wkfile.oven_temp.init_value;
  Deta_Table.temp_setpt = Active_Wkfile.deta_temp.init_value;
  Detb_Table.temp_setpt = Active_Wkfile.detb_temp.init_value;
  Inja_Table.temp_setpt = Active_Wkfile.inja_temp.init_value;
  Injb_Table.temp_setpt = Active_Wkfile.injb_temp.init_value;
  Auxa_Table.temp_setpt = Active_Wkfile.auxa_temp.init_value;
  Auxb_Table.temp_setpt = Active_Wkfile.auxb_temp.init_value;

  /* Do the same for the filtered setpoint, but multiply by 256 since  */
  /* the filtered setpoints are stored in 64*256 degrees.              */

  Oven_Table.filt_temp_setpt = Active_Wkfile.oven_temp.init_value << 8;
  Deta_Table.filt_temp_setpt = Active_Wkfile.deta_temp.init_value << 8;
  Detb_Table.filt_temp_setpt = Active_Wkfile.detb_temp.init_value << 8;
  Inja_Table.filt_temp_setpt = Active_Wkfile.inja_temp.init_value << 8;
  Injb_Table.filt_temp_setpt = Active_Wkfile.injb_temp.init_value << 8;
  Auxa_Table.filt_temp_setpt = Active_Wkfile.auxa_temp.init_value << 8;
  Auxb_Table.filt_temp_setpt = Active_Wkfile.auxb_temp.init_value << 8;

  INTERRUPTS_ON
}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void UpdatePneuRampInitValues( void )

/**end_proto**/
{

   *Col1_Pres_Info.setpoint = GetRampInitValue( &Col1_Pres_Info );
   *Col2_Pres_Info.setpoint = GetRampInitValue( &Col2_Pres_Info );
   *Aux3_Pres_Info.setpoint = GetRampInitValue( &Aux3_Pres_Info );
   *Aux4_Pres_Info.setpoint = GetRampInitValue( &Aux4_Pres_Info );
   *Aux5_Pres_Info.setpoint = GetRampInitValue( &Aux5_Pres_Info );

}

